#include "mainwindow.h"
#include "textprocessor.h"
#include "dbmgr.h"
#include "filemgr.h"

#include <QApplication>

#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

int main(int argc, char *argv[])
{
#if 0
    TextProcessor tp;
    shared_ptr<string> text = make_shared<string>("");

    string path = "E:/code/qt/pdep/dummy/dummy.cpp";

    ifstream in(path);
    stringstream buffer;
    buffer << in.rdbuf();
    string inputText = buffer.str();

    shared_ptr<vector<string>> headerList = tp.ExtractHeader(inputText);
    for (auto &s : *headerList)
    {
        cout << s << endl;
    }
#endif
//    cout << dm.OpenDB(string("D:/haha.db")) << endl;
//    dm.InsertFile(string("fullpath"), string("basename"), 1, 0);
//    shared_ptr<vector<FileInfo>> files = dm.QueryFile(-1, string(""), string(""), -1, -1);
//    cout << files->at(0).id << files->at(0).fullpath << files->at(0).basename << files->at(0).type << files->at(0).thirdparty << endl;

//    dm.InsertDep(1, 2);
//    shared_ptr<vector<DepInfo>> deps = dm.QueryDep(-1, -1, -1);
//    cout << deps->at(0).id << deps->at(0).left << deps->at(0).right << endl;
    //shared_ptr<vector<TypeInfo>> types = dm.QueryType(-1, string(""));

    //cout << types->at(0).suffix << endl;
    shared_ptr<DBMgr> dm = make_shared<DBMgr>();

#if 0
    dm->CreateDB(string("D:/haha.db"));
    dm->InsertType(string("c"));
    dm->InsertType(string("h"));
    dm->InsertType(string("cpp"));
    shared_ptr<vector<TypeInfo>> typeList = dm->QueryType(-1, string(""));

    FileMgr fm(dm, typeList);
    cout << dm->transaction() << endl;
    fm.TraverseFile(string("E:/source/glibc-2.23"));
    cout << dm->commit() << endl;
#else
#if 0
    dm->OpenDB(string("D:/haha.db"));
    shared_ptr<vector<FileInfo>> pf = dm->QueryFile(-1, string(""), string(""), -1, -1, -1, -1);
    for (FileInfo f : *pf)
    {
        TextProcessor tp;
        shared_ptr<string> text = make_shared<string>("");

        string path = f.fullpath;

        ifstream in(path);
        stringstream buffer;
        buffer << in.rdbuf();
        string inputText = buffer.str();

        shared_ptr<vector<string>> headerList = tp.ExtractHeader(inputText);
        for (auto &s : *headerList)
        {
            cout << s << endl;
        }

        cout << f.fullpath << endl;
    }
#endif
#endif

    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
    return 0;
}
